/*
 * Copyright@www.it1997.com.
 * @Author: 陈晓晨
 * @Date: 2020/7/1
 * Description:版权所有 QQ:376231445
 */

package com.it1997.it1997admin;

import cn.hutool.core.io.file.FileWriter;
import com.it1997.it1997admin.pojo.KsData;
import com.it1997.it1997admin.service.ExtractDataService;
import com.it1997.it1997admin.service.UserService;
import com.it1997.it1997admin.vo.AdminVo;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStream;
import com.itextpdf.text.pdf.PdfWriter;
import lombok.extern.log4j.Log4j2;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;


import java.io.*;
import java.util.List;


@Log4j2
/*@SpringBootTest
@RunWith(SpringRunner.class)*/
public class ExtractData {
    /*@Autowired
    private UserService userService;
    @Autowired
    private ExtractDataService extractDataService;
    @Test
   public void test() throws FileNotFoundException {
      *//* List<AdminVo> adminVoList= userService.getAdminList();
       log.info(adminVoList);*//*
        Integer allData=336;
        Integer rate=20;
        Integer extractKSData=20;
        String FONT = "/static/font.ttf";
        Font f1 = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED,40);

        //随机抽取20%的考点
        List<KsData> allKd = extractDataService.getAllKd(allData,rate);
        log.info(allKd);
        log.info(allKd.size());
        for (KsData KDDM:allKd){
            //每个考点随机抽取5位考生
            try {
            List<KsData> ksDataList=extractDataService.getRandomKs(KDDM.getKDDM(),extractKSData);
            log.info(ksDataList);
               *//* String dir="E:/data/new/"+KDDM;
                File file=new File(dir);
                if(!file.exists()){
                    file.mkdir();
                }*//*
                String NewPath="D:/data/new/"+KDDM+".pdf";
                Document document = new Document();
                PdfWriter.getInstance(document,new FileOutputStream(NewPath));
                document.open();

            for (KsData KS:ksDataList){
                String imgPath="D:/data/img/"+KS.getKSH()+".jpg";
                Image image = Image.getInstance(imgPath);
                image.setAlignment(Image.MIDDLE);
                image.scaleAbsolute(300,300);
                    document.add(new Paragraph("姓名："+KS.getXM(),f1));
                    document.add(new Paragraph("考场："+KS.getKCDM(),f1));
                    document.add(new Paragraph("证件号："+KS.getZJHM(),f1));
                    document.add(new Paragraph("座号："+KS.getZH(),f1));
                    document.add(image);
                    document.add(new Paragraph("=======华丽分割线=====",f1));
                 }
                document.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }


   }*/
}